package services.common;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import models.common.entity.t_bank_list;
import services.base.BaseService;

import common.utils.Factory;
import common.utils.PageBean;

import daos.common.BankListDao;

/**
 * 银行列表service实现
 * 
 * @description 
 *
 * @author ChenZhipeng
 * @createDate 2015年12月23日
 */
public class BankListService extends BaseService<t_bank_list> {

	private BankListDao bankListDao = Factory.getDao(BankListDao.class);
	
	protected BankListService() {
		super.basedao = this.bankListDao;
	}

	/**
	 * 查询银行列表
	 * @description 
	 *
	 * @author Chenzhipeng
	 * @createDate 2015年12月25日
	 * @param userId
	 * @return
	 */
	public List<t_bank_list> queryAllBankList() {
		
		return bankListDao.findListByColumn(" 1=1 ORDER BY id asc");
	}
	
	/**
	 * 
	 * @Title: pageOfBanks 
	 * @param  
	 * @return: PageBean<t_bank_list>
	 * @author: liaijun   
	 * @date: 2017年10月17日 上午10:43:59 
	 * @version: V1.0
	 */
	public PageBean<t_bank_list> pageOfBanks(int currPage, int pageSize,String bankName){
		if (bankName == null) {
			String sqlCount = "select count(1) from t_bank_list";
			String sqlQuery = "select id,code,name,bank_no from  t_bank_list";
			return bankListDao.pageOfBySQL(currPage, pageSize, sqlCount, sqlQuery, null);
		}else {
			String sqlCount = "select count(1) from t_bank_list where name like :bankName";
			String sqlQuery = "select id,code,name,bank_no from  t_bank_list where name like :bankName";
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("bankName", "%"+bankName+"%");
			return bankListDao.pageOfBySQL(currPage, pageSize, sqlCount, sqlQuery, map);
		}
		
	}
	
	public boolean save(t_bank_list t)
	{
		return bankListDao.save(t);
	}
	
	/**
	 * 删除银行信息
	 * @Title: delete 
	 * @param  
	 * @return: int
	 * @author: liaijun   
	 * @date: 2017年10月17日 下午12:53:16 
	 * @version: V1.0
	 */
	public int delete(long id){
		String sql = "delete from  t_bank_list where id = :id ";
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("id", id);
		return bankListDao.executSQL(sql, map);
	}
}
